The function getPdo() creates a PDO connection to the MySQL database using UTF8MB4 encoding
and exception-based error handling. It uses global configuration variables for host, database name,
user, password and port.
parseCueTimes($cueString) parses a RadioDJ-style cue string (e.g. sta=0&int=5&out=180)
into an associative array with keys like sta, int, out, end, etc.
If the string is empty or only &, it returns default values (all zeros).
getEnergyScore($track) calculates a 0–10 “energy score” based on BPM and intro/outro length.
Higher BPM and shorter intros/outros increase the score. This is later used to sort the playlist into a
smoother “energy flow”.
extractSweeperId($value) strips a leading & from a sweeper reference and returns
an empty string if no sweeper is present.
buildRDJDataLine($track) builds a #RDJDATA: line containing:
track ID, cue points (start, intro, end, outro, hooks, etc.) and an optional sweeper ID.
This line is written into the M3U so RadioDJ can read cue data directly from the playlist.
In preset mode (when bpmmode is not manual), the script:
After selecting tracks, the script writes an M3U file:
#EXTM3U#EXTINF:duration,Artist - Title#RDJDATA: line from buildRDJDataLine()It logs the filename, track count and total duration, and returns these values.
In manual mode, the script:
hours * 3600 seconds.It then tries to fill the target duration as closely as possible, first by adding tracks, then by fine-tuning the remaining seconds with exact or near matches.
Once the playlist is built, it is sorted using getEnergyScore() into a “wave” pattern:
medium-energy tracks near the center, higher/lower energy tracks towards the edges.
If two tracks have the same wave value, tie-breaking uses outro length and then intro length
to improve transitions.
The final playlist is written to an M3U file in the same format:
#EXTM3U, followed by #EXTINF, path and #RDJDATA for each track.
If the user submits the form with a reset field, the script redirects to the same URL
without query parameters, effectively clearing the form and state.
The script sets up:
.m3u files for the remix dropdown.
It loads all genres from the genre table and uses them to populate a multi-select list
in the UI.
On POST, the script:
$filters array passed into generatePlaylist().If the user selects an existing M3U file and enters a new filename:
#EXTINF, path, #RDJDATA).#EXTM3U header.?done=newfile.m3u to trigger the preview.If no M3U is chosen, the script:
generatePlaylist($hours, $filters, $logMessage).?done=filename.m3u on success, or shows an error on failure.
When ?done=filename.m3u is present, the script:
The HTML form includes:
Submitting this form without choosing an existing M3U triggers new playlist generation.
A second fieldset lets the user:
If a playlist was created or remixed, the page shows:
A small floating button appears when the user scrolls down. It:
This completes the full English documentation of your M3U Maker: database, helpers, playlist logic, M3U writing, remixing, UI and preview.